﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
namespace Z2.Core
{

	#region Using

	using Microsoft.Xna.Framework;
	using Microsoft.Xna.Framework.Graphics;

	#endregion

	/// <summary>
	/// Třída definující políčko mapy
	/// </summary>
	public class WorldField
	{

		#region Const

		public const int SIZE = 32; // Velikost políčka

		#endregion

		#region Members

		private Sprite m_sprite;
		private bool m_isFront;
		private bool m_isWater;
		private bool m_isSolid;

		#endregion

		#region Constructor

		/// <summary>
		/// Konstruktor
		/// </summary>
		/// <param name="definition">Definice</param>
		public WorldField(FieldDefinition definition)
		{
			this.IsWater = (definition.Graphics == "water");
			this.m_isSolid = definition.Solid;
			this.m_sprite = SpriteManager.Instance.LoadSpriteCache(
				definition.Graphics, 
				definition.FramesX, 
				definition.FramesY, 
				World.WORLD_DIR);
		}

		#endregion

		#region Methods
		
		/// <summary>
		/// Metoda vykreslí toto políčko
		/// </summary>
		/// <param name="batch"></param>
		/// <param name="position"></param>
		public void Draw(SpriteBatch batch, Vector2 position)
		{
			float depth = this.m_sprite.Depth;
			this.m_sprite.Depth = this.m_isFront? 1F : depth;
			this.m_sprite.Draw(batch, position);
			this.m_sprite.Depth = depth;
		}
		
		#endregion

		#region Properties

		public Sprite Sprite
		{
			get { return this.m_sprite; }
		}

		public bool IsSolid
		{
			get { return this.m_isSolid; }
		}

		/// <summary>
		/// Vrací nebo nastavuje zda je toto políčko typem voda
		/// </summary>
		public bool IsWater
		{
			get { return this.m_isWater; }
			set { this.m_isWater = value; }
		}

		/// <summary>
		/// Vrací nebo nastavuje kde se toto políčko vykreslí
		/// </summary>
		public bool IsFront
		{
			get { return this.m_isFront; }
			set { this.m_isFront = value; }
		}

		#endregion

	}
}
